package com.ganeshkrishnan.globald.model;

import java.util.Date;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import com.ganeshkrishnan.globald.abstracts.BaseObject;

@Entity
public class PersonLocation extends BaseObject {
	private static final long	serialVersionUID	= 1L;
	private Long				ID;
	//Latitude of the city
	private float				latitude;
	//longitude of the city
	private float				longitude;
	//Type of city. Home =0,satellites=1, Colonized=2, base=2
	private int					locationType		= 2;
	//pointer to deployment table for army
	//	private int deployment;
	private Set<Deployment>		deployment;
	private Date				dateCreated;

	private Person				person;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getID() {
		return ID;
	}

	public void setID(Long iD) {
		ID = iD;
	}

	@ManyToOne
	@JoinColumn(name = "PersonID", referencedColumnName = "ID")
	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public float getLatitude() {
		return latitude;
	}

	public void setLatitude(float latitude) {
		this.latitude = latitude;
	}

	public float getLongitude() {
		return longitude;
	}

	public void setLongitude(float longitude) {
		this.longitude = longitude;
	}

	public int getLocationType() {
		return locationType;
	}

	public void setLocationType(int locationType) {
		this.locationType = locationType;
	}

	@OneToMany(fetch = FetchType.EAGER)
	@JoinColumn(name = "LocationID")
	public Set<Deployment> getDeployment() {
		return deployment;
	}

	public void setDeployment(Set<Deployment> deployment) {
		this.deployment = deployment;
	}

	public Date getDateCreated() {
		return dateCreated;
	}

	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;
		PersonLocation ForLoc = (PersonLocation) o;
		if (latitude == ForLoc.getLatitude() && longitude == ForLoc.getLongitude()) {
			return true;
		}
		return false;
	}

	@Override
	public int hashCode() {
		return (person != null ? person.hashCode() : 0) + locationType
				+ ((dateCreated != null) ? dateCreated.toString().hashCode() : 1);
	}

	@Override
	public String toString() {
		return "PersonLocation " + locationType + " " + person;
	}
}
